package controller;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.AppCategory;
import pojo.DataDictionary;
import service.CategoryService;
import service.DataService;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/cate")
public class CateController {
    @Resource
    private CategoryService categoryService;
    @Resource
    private DataService dataService;

    @GetMapping(value = "/levellist1"/*,produces = {"application/json;charset=utf-8"}**/)
    @ResponseBody
    public String levelList1(Integer pid){
        List<AppCategory> categoryLevel1List = categoryService.cateList(pid);
        return JSON.toJSONString(categoryLevel1List);
    }

    @GetMapping(value = "/levellist2"/*,produces = {"application/json;charset=utf-8"}**/)
    @ResponseBody
    public String levelList2(Integer pid){
        List<AppCategory> categoryLevel2List = categoryService.cateList(pid);
        return JSON.toJSONString(categoryLevel2List);
    }

    @GetMapping(value = "/levellist3"/*,produces ={"application/json;charset=utf-8"}**/)
    @ResponseBody
    public String levelList3(Integer pid){
        List<AppCategory> categoryLevel3List = categoryService.cateList(pid);
        return JSON.toJSONString(categoryLevel3List);
    }

    @GetMapping(value = "/datalist"/*,produces ={"application/json;charset=utf-8"}**/)
    @ResponseBody
    public String datalist(String tcode){
        List<DataDictionary> flatFormList = dataService.ddList(tcode);
        return JSON.toJSONString(flatFormList);
    }}
